#include <iostream>
#include <memory>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
using std::shared_ptr;

void test0(){
    shared_ptr<int> sp(new int(10));
    cout << "*sp:" << *sp << endl;
    cout << sp.get() << endl;

    //复制操作
    cout << endl;
    shared_ptr<int> sp2 = sp;
    cout << "*sp:" << *sp << endl;
    cout << sp.get() << endl;
    cout << "*sp2:" << *sp2 << endl;
    cout << sp2.get() << endl;

    cout << sp.use_count() << endl;
    cout << sp2.use_count() << endl;

    //赋值操作
    cout << endl;
    shared_ptr<int> sp3(new int(20));
    sp2 = sp3;
    cout << sp.use_count() << endl;
    cout << sp2.use_count() << endl;
    cout << sp3.use_count() << endl;

    //作为容器元素
    vector<shared_ptr<int>> vec;
    vec.push_back(sp);
    vec.push_back(std::move(sp2));
}

void test1(){
    int * p = new int(1);
    shared_ptr<int> sp(p);
    shared_ptr<int> sp2(sp);
}


int main(void){
    test1();
    return 0;
}
